import es
import gamethread
import playerlib
import popuplib
import weaponlib
import usermsg
import cfglib
import cmdlib
import langlib
import installlib
import effectlib
import vecmath
import cPickle
import os
import time
import random
import math

# psyco, more unstable but a lot faster
import psyco
psyco.full() 


# Set the addon info data
wcspVersion = '0.0.1'
info          = es.AddonInfo()
info.name     = 'Warcraft: Source Python'
info.version  = wcspVersion
info.url      = 'None'
info.basename = 'wcsp'
info.author   = 'Seek'

playerDict = {}
raceDict = {}
adminDict = {}
assistedDict = {}

text = None
sv = es.ServerVar
addonPath = es.getAddonPath('wcsp')

servervars = {
'wcs_assistedxp' : [1, "Enables/Disables assisted experience"],
'wcs_restedxp' : [1, "Enables/Disables rested experience"],
'wcs_awaytime' : [7, "Number (in days) a player must be away before receiving rested experience"]
}

commands = {
'wcshelp' : [, ''],
'wcsmenu' : [, ''],
'wcsrank' : [, ''],
'wcstop10' : [, ''],
'changerace' : [, ''],
'raceinfo' : [, ''],
'playerinfo' : [, ''],
'spendskills' : [, ''],
'resetskills' : [, ''],
'wcsadmin' : [, ''],
'shopinfo' : [, ''],
'shopmenu' : [, ''],
'showskills' : [, ''],
'skillinfo' : [, ''],
'wcsadmin' : [, ''],
'+ability' : [AbilityOn, ''],
'-ability' : [AbilityOff, ''],
'+ability2' : [AbilityOn2, ''],
'-ability2' : [AbilityOff2, ''],
'+ability3' : [AbilityOn3, ''],
'-ability3' : [AbilityOff3, ''],
'+ability4' : [AbilityOn4, ''],
'-ability4' : [AbilityOff4, '']
}

def load():
    global text
    text = langlib.Strings(addonPath + '/strings.ini')
    
def player_activate(ev):
    userid = ev['userid']
    uid = playerlib.uniqueid(userid, True)
    
    # If player has joined the server before
    if uid in playerDict:
        if sv(wcs_restedxp) != 0:
            es.tell(userid, '#multi', text())
            lastsession = playerDict[uid]['last_session']
            delta = time.time() - lastsession
            if delta >= sv('wcs_awaytime'):
                playerDict[uid]['restedxp'] = 1
            else:
                playerDict[uid]['restedxp'] = 0
                
    playerDict[uid]['last_session'] = time.time()
    
def AbilityOn():
    es.getUserIdList()
def AbilityOff():
    es.getUserIdList()
def AbilityOn2():
    es.getUserIdList()
def AbilityOff2():
    es.getUserIdList()
def AbilityOn3():
    es.getUserIdList()
def AbilityOff3():
    es.getUserIdList()
def AbilityOn4():
    es.getUserIdList()
def AbilityOff4():
    userid = es.
    